﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EuroManager.Domain.Simulator.Engine;
using EuroManager.Domain.Simulator.Helpers;
using EuroManager.Domain.Simulator.World;
using NUnit.Framework;

namespace EuroManager.Domain.Simulator.Tests.World
{
    [TestFixture]
    public class PitchTests
    {
        [Test]
        public void ShouldHavePositiveWidth()
        {
            Pitch pitch = new Pitch();

            Assert.IsTrue(pitch.Width > 0);
        }

        [Test]
        public void ShouldHavePositiveHeight()
        {
            Pitch pitch = new Pitch();

            Assert.IsTrue(pitch.Height > 0);
        }

        [Test]
        public void ShouldExposeCenterAsTheMiddleOfWidth()
        {
            Pitch pitch = new Pitch();

            Assert.AreEqual(pitch.Center.X, pitch.Width / 2, Maths.Epsilon);
        }

        [Test]
        public void ShouldExposeCenterAsTheMiddleOfHeight()
        {
            Pitch pitch = new Pitch();

            Assert.AreEqual(pitch.Center.Y, pitch.Height / 2, Maths.Epsilon);
        }

        [Test]
        public void ShouldExposeLeftSideGoalLocationOnTheLeft()
        {
            Pitch pitch = new Pitch();
            Vector2D location = pitch.GoalLocation(PitchSide.Left);

            Assert.IsTrue(location.X < pitch.Center.X);
        }

        [Test]
        public void ShouldExposeRightSideGoalLocationOnTheRight()
        {
            Pitch pitch = new Pitch();
            Vector2D location = pitch.GoalLocation(PitchSide.Right);

            Assert.IsTrue(location.X > pitch.Center.X);
        }

        [Test]
        public void ShouldMapToMetricalLocationForLeftSide()
        {
            Pitch pitch = new Pitch();
            Vector2D location = pitch.MapToMetricalLocation(PitchSide.Left, new Vector2D(0.75f, 0.75f));

            Assert.AreEqual(0.75f * pitch.Width, location.X, Maths.Epsilon);
            Assert.AreEqual(0.75f * pitch.Height, location.Y, Maths.Epsilon);
        }

        [Test]
        public void ShouldMapToMetricalLocationForRightSide()
        {
            Pitch pitch = new Pitch();
            Vector2D location = pitch.MapToMetricalLocation(PitchSide.Right, 0.75f, 0.75f);

            Assert.AreEqual(0.25f * pitch.Width, location.X, Maths.Epsilon);
            Assert.AreEqual(0.25f * pitch.Height, location.Y, Maths.Epsilon);
        }

        [Test]
        public void ShouldMapToProportionalLocationForLeftSide()
        {
            Pitch pitch = new Pitch();

            Vector2D location = pitch.MapToProportionalLocation(PitchSide.Left, 0.75f * pitch.Width, 0.75f * pitch.Height);

            Assert.AreEqual(0.75f, location.X, Maths.Epsilon);
            Assert.AreEqual(0.75f, location.Y, Maths.Epsilon);
        }

        [Test]
        public void ShouldMapToProportionalLocationForRightSide()
        {
            Pitch pitch = new Pitch();

            Vector2D location = pitch.MapToProportionalLocation(PitchSide.Right, new Vector2D(0.75f * pitch.Width, 0.75f * pitch.Height));

            Assert.AreEqual(0.25f, location.X, Maths.Epsilon);
            Assert.AreEqual(0.25f, location.Y, Maths.Epsilon);
        }
    }
}
